package com.ys.web.yinsheng.manager;

import com.ys.utils.base.j2se.Convert;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.redis.Redis;
import com.ys.utils.spring.config.SystemError;
import com.ys.utils.spring.properties.Config;

public class YsWalletManager {

    public static void checkUserLevel(String uid,String amount,int realIdCardUp,int bankCount){
        String key = String.format("ys:user:level:amount:%s",uid);
        String oldAmount = Redis.str.get(key);
        if (!Boolean.parseBoolean(Config.pp.get("ys.bank.bind.number.check.isopen"))) {
            bankCount = 1;
        }
        boolean flag = false;
        int newAmount = Convert.objToInt(amount)+Convert.objToInt(oldAmount);
        //上传了身份证，绑定2张或者以上卡，额度20w
        if(realIdCardUp==2 && bankCount>1 && newAmount<StringHandler.getLong(Config.pp.get("ys.bank.out.money.level.3"))){
            flag = true;
        }else if(realIdCardUp==2 && bankCount>0 && newAmount<StringHandler.getLong(Config.pp.get("ys.bank.out.money.level.2"))){
            //上传了身份证，绑定一张卡，额度10w
            flag = true;
        }else if (realIdCardUp==1 && bankCount>0 && newAmount<StringHandler.getLong(Config.pp.get("ys.bank.out.money.level.2"))){
            //没上传身份证，绑定了卡，额度10w
            flag = true;
        }
        else if(bankCount==0){
            //没上传身份证，没绑卡，额度1000
            flag = true;
            SystemError.wrapBs("500","请先绑定银行卡");
        }
        Redis.str.set(key,Convert.objToStr(newAmount));
        if(!flag){
            SystemError.wrapBs("500","账户权限不足，请提升账户权限");
        }
    }
}
